package practise.alogrithm.hundredInterviewQuestions.secondTime;

import practise.alogrithm.introductionToAlogrithm.dataStructures.TwoQueueStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Richard on 7/26/2014.
 */
public class TwoElementsInArrayAsSum {
    public List<List<Integer>> find(List<Integer> array , Integer sum){
        List<List<Integer>> result = new ArrayList<>();
        if(array.isEmpty()){
            throw new IllegalArgumentException();
        }
        for(int index=0; index<array.size()/2;index++){
            if(array.get(index)+array.get(array.size()-1-index)==sum){
                result.add(new ArrayList<>(Arrays.asList(new Integer[]{array.get(index),array.get(array.size()-1-index)})));
            }
        }

        return result;
    }

    public static void main(String[] args){
        TwoElementsInArrayAsSum twoElementsInArrayAsSum = new TwoElementsInArrayAsSum();
        System.out.print(twoElementsInArrayAsSum.find(new ArrayList<Integer>(Arrays.asList(new Integer[]{1,2,3,4,5,6})),7));
    }
}
